package com.arrogames.blondbattle.game.graphics 
{
	
	import com.arrogames.blondbattle.game.graphics.animation.Destroyable;
	import starling.display.Sprite;
	import starling.display.MovieClip;
	import starling.events.Event;
	import starling.textures.TextureAtlas;
	import starling.textures.Texture;
	
	import starling.core.Starling;
	
	import com.arrogames.blondbattle.assets.AssetManager;
	
	/**
	 * ...
	 * @author Arnoud van Steenwijk
	 */
	public class BaseExplosionView extends Sprite implements Destroyable
	{

		private var explosionMovie:MovieClip;
		private var animationEnded:Boolean = false;
		private var textureName:String = "";
		
		public function BaseExplosionView(pName:String) 
		{
			textureName = pName.toLowerCase();
			var frames:Vector.<Texture> = AssetManager.instance.getTextures("explode_big");
			explosionMovie = new MovieClip(frames);
			explosionMovie.loop = false;
			explosionMovie.addEventListener("complete", _explosionComplete);
			addChild(explosionMovie);
			Starling.juggler.add(explosionMovie);
			
			pivotX = explosionMovie.width / 2;
			pivotY = explosionMovie.height / 2;
		}
		
		/**	
		 * Destroy the animation components
		 */
		public function destroy() : void 
		{
			removeChild(explosionMovie);
			Starling.juggler.remove(explosionMovie);
			animationEnded = true;
		}
		
		/**
		 * Event received when the animation completes
		 * Dispatches an animation complete event to be handled by any listeners
		 * 
		 * @param	pEvent	Event
		 */
		private function _explosionComplete(pEvent:Event) : void
		{
			destroy();
		}
		
		/**
		 * Check if the animation has ended, which means the view can potentially be cleaned up
		 * 
		 * @return Boolean
		 */
		public function getAnimationEnded() : Boolean
		{
			return animationEnded;
		}
		
	}

}